package correiosDados;

import correios.BadCEPException;
import correios.Utils;

public class CEP {
	
	//Attributes
	private String value;
	
	//Methods

	public CEP(String v) throws BadCEPException{
		this.setValue(v);
	}
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) throws BadCEPException{
		if(value == null){
			throw new BadCEPException();
		}
		if(value.length() != 9 || value.charAt(5) != '-'){
			throw new BadCEPException();
		}
		for(int i = 0; i < 9 ; i++){
			if(i == 5) i++;
			if(!Utils.isDigit(value.charAt(i))) throw new BadCEPException();
		}
		this.value = value;
	}
	
}
